#include <iostream>
using namespace std;

//函数模板
template <typename T>
void swapTwo(T &t1,T &t2) {
    T temp = t1;
    t1 = t2;
    t2 = temp;
}

//实现一个排序函数
template <typename T>
void mySort(T arr[],int len) {
    for(int i = 0;i < len;i++) {
        int max = i;//认定最大值的下标
        for(int j = i +1;j < len;j++) {
            if(arr[max] < arr[j]) {
                max = j;
            }
        }
        if(max != i) {
            swapTwo(arr[i],arr[max]);
        }
    }
}

template <typename T>
void printArray(const T t[],int len) {
    for(int i = 0;i < len;i++) {
        cout<<t[i]<<" ";
    }
    cout<<endl;
}

int main() {
/*    double a = 3;
    double b = 4;
    swapTwo(a,b);
    swapTwo<double >(a,b);
    cout<<a<<"\t"<<b<<endl;*/

    char charArray[] = "sddaaddfdasef";
    int intArray[] = {0,12,3,1,213,1,3};

    mySort(charArray, sizeof(charArray)/ sizeof(char));
    mySort(intArray, sizeof(intArray)/ sizeof(int));

    printArray(charArray,sizeof(charArray)/ sizeof(char));
    printArray(intArray, sizeof(intArray)/ sizeof(int));
}